package com.singzi.leetcode.N1100;

import java.util.Stack;

public class T1020 {
    public static void main(String[] args) {
        Solution20 s20 = new Solution20();
        System.out.println(s20.isValid("()"));
    }
}
class Solution20 {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<Character>();
        for(char c:s.toCharArray()){
            if(c=='(')
                stack.push(')');
            else if(c=='[')
                stack.push(']');
            else if(c=='{')
                stack.push('}');
            else if(stack.isEmpty()||c!=stack.pop()){
                return false;
            }
        }
        return stack.isEmpty();

    }
}